<template>
	
	 
	<el-form-item label="">
		<h1>头图</h1>
		<el-upload class="avatar-uploader" :data="jm()" :key="form.images" :action="`${api}/index.php/index/Goods/uploadVideo`"
			:show-file-list="false" :on-success="(file)=>{editimgsProps(file,'images')} ">
				<img v-if="ifType(form.images)=='image'" :src="ifImgHeader(form.images)" class="avatar" />
				<video v-if="ifType(form.images)=='video'" style="width:100%;" class="el-upload-list__item-thumbnail" controls=""
					:src="ifImgHeader(form.images)">
				</video>
			
			
			<i v-if="!form.images" class="el-icon-plus avatar-uploader-icon"></i>
			
		</el-upload>
	</el-form-item>
	<editor-wang :value="contents" @change="changeWang"></editor-wang>
	<el-button class="mb20" style="margin-top: 30px;" @click="submit" type="primary">保存</el-button>
</template>

<script lang="ts">
	import {
		ElMessageBox,
		ElMessage
	} from 'element-plus'
	import editorWang from '../components/wangEnduit'
	export default {
		components:{
			editorWang
		},
		data() {
			return {
				formLabelWidth: '120px',
				isshow:1, //是否显示 1显示
				tuijian:0, //是否推荐  0 否
				form: {
					name: '',
					id: '',
					digest:"",
					contents:"",
					alink:"",
					images:"",
					sort:"" ,//排序			
				},
				contents:"",
				rules: {
				        name: [
				          {
				            required: true,
				            message: '请填写新闻名称',
				            trigger: 'blur',
				          }
				        ],
						pid: [
						  {
						    required: true,
						    message: '请选择所属新闻',
						    trigger: 'change',
						  }
						],
				},
				pid: []
			}
		},
		mounted() {
			this.getData();
		},
		methods: {
			
            changeWang(html) {
				console.log(html)
				this.form.contents=html;
			    
			},
			getData() {
				this.$http.post("/index.php/index/Goods/serviceshow").then(data => {
					this.form = data[0];
					this.id = this.form.id;
					this.contents= this.form.contents;
					

				})
			},
			submit(ref) {
				
				if (this.id) this.form.id = this.id;
				
				
				
				this.$http.post(this.id ? '/index.php/index/Goods/serviceedit' : "/index.php/index/Goods/newsadd",
					this.form).then(data => {
				
					ElMessage({
						message: this.id ? '编辑成功' : '新增成功',
						type: 'success',
					})
					this.getData();
				})
				
			},
			remove(data){
				this.$http.post("/index.php/index/Goods/newsdel",{id:data.row.id}).then(data => {
					ElMessage({
						message: '删除成功' ,
						type: 'success',
					})
					this.getData();
				})
			},
			handleAvatarSuccess(file) {

				this.form.image = file.data;
			},
			


		}
	}
</script>
